#pragma once

#include "common.hpp"
#include "Socket.hpp"



#define DEFAULT_BACKLOG 16
using io_service_t = std::function<void(std::shared_ptr<Socket>&, const Inet_Addr&)>;

class client_tcp : public no_copy
{
public:
    client_tcp(uint16_t server_port, const std::string& server_ip, const io_service_t& io_service)
        :_tcp_connect_socket_ptr(std::make_unique<TCP_Socket>())//父类指针指向子类, 实现多态
        ,_server_port(server_port)
        ,_server_ip(server_ip)
        ,_io_service(io_service)
    {
        _tcp_connect_socket_ptr->create_connect_socket(_server_port, _server_ip);
    }

    void start()
    {
        Inet_Addr server(_server_port, _server_ip);
        _io_service(_tcp_connect_socket_ptr, server);
    }


private:
    std::shared_ptr<Socket> _tcp_connect_socket_ptr;//父类指针
    uint16_t _server_port;
    std::string _server_ip;

    io_service_t _io_service;//由上层(protocol提供)传入
};
